/**
 * @license
 * Copyright 2013 Google Inc. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 *
 * @fileoverview Public domain parameters for NIST curves.
 * @author thaidn@google.com (Thai Duong)
 */

goog.provide('e2e.ecc.constant');


// Define the namespaces for the subsequent constants.
// TODO(user): Make typesafe.
/** @type {Object} */
e2e.ecc.constant.P_256 = {};


/** @type {Object} */
e2e.ecc.constant.P_384 = {};


/** @type {Object} */
e2e.ecc.constant.P_521 = {};


/** @type {Object} */
e2e.ecc.constant.CURVE_25519 = {};


/**
 * The field order, e.g., 2^224 (2^32 - 1) + 2^192 + 2^96 - 1.
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.P_256.Q = [
  0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];


/**
 * The B coefficient in the equation of the elliptic curve.
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.P_256.B = [
  0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7,
  0xB3, 0xEB, 0xBD, 0x55, 0x76, 0x98, 0x86, 0xBC,
  0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6,
  0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B];


/**
 * The base point in uncompressed form.
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.P_256.G = [0x04, /* uncompressed */
  // x
  0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47,
  0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2,
  0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0,
  0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96,
  // y
  0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B,
  0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16,
  0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE,
  0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5];


/**
 * The order of the base point.
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.P_256.N = [
  0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84,
  0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51];


/**
 * The field order 2^384 - 2^128 - 2^196 + 2^32 - 1
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.P_384.Q = [
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
  0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff];


/**
 * The B coefficient in the equation of the elliptic curve.
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.P_384.B = [
  0xb3, 0x31, 0x2f, 0xa7, 0xe2, 0x3e, 0xe7, 0xe4,
  0x98, 0x8e, 0x05, 0x6b, 0xe3, 0xf8, 0x2d, 0x19,
  0x18, 0x1d, 0x9c, 0x6e, 0xfe, 0x81, 0x41, 0x12,
  0x03, 0x14, 0x08, 0x8f, 0x50, 0x13, 0x87, 0x5a,
  0xc6, 0x56, 0x39, 0x8d, 0x8a, 0x2e, 0xd1, 0x9d,
  0x2a, 0x85, 0xc8, 0xed, 0xd3, 0xec, 0x2a, 0xef];


/**
 * The base point in uncompressed form.
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.P_384.G = [0x04, /* uncompressed */
  // x
  0xaa, 0x87, 0xca, 0x22, 0xbe, 0x8b, 0x05, 0x37,
  0x8e, 0xb1, 0xc7, 0x1e, 0xf3, 0x20, 0xad, 0x74,
  0x6e, 0x1d, 0x3b, 0x62, 0x8b, 0xa7, 0x9b, 0x98,
  0x59, 0xf7, 0x41, 0xe0, 0x82, 0x54, 0x2a, 0x38,
  0x55, 0x02, 0xf2, 0x5d, 0xbf, 0x55, 0x29, 0x6c,
  0x3a, 0x54, 0x5e, 0x38, 0x72, 0x76, 0x0a, 0xB7,
  // y
  0x36, 0x17, 0xde, 0x4a, 0x96, 0x26, 0x2c, 0x6f,
  0x5d, 0x9e, 0x98, 0xbf, 0x92, 0x92, 0xdc, 0x29,
  0xf8, 0xf4, 0x1d, 0xbd, 0x28, 0x9a, 0x14, 0x7c,
  0xe9, 0xda, 0x31, 0x13, 0xb5, 0xf0, 0xb8, 0xc0,
  0x0a, 0x60, 0xb1, 0xce, 0x1d, 0x7e, 0x81, 0x9d,
  0x7a, 0x43, 0x1d, 0x7c, 0x90, 0xea, 0x0e, 0x5f];


/**
 * The order of the base point.
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.P_384.N = [
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xc7, 0x63, 0x4d, 0x81, 0xf4, 0x37, 0x2d, 0xdf,
  0x58, 0x1a, 0x0d, 0xb2, 0x48, 0xb0, 0xa7, 0x7a,
  0xec, 0xec, 0x19, 0x6a, 0xcc, 0xc5, 0x29, 0x73];


/**
 * The field order 2^521 - 1
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.P_521.Q = [
  0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff];


/**
 * The B coefficient in the equation of the elliptic curve.
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.P_521.B = [
  0x00, 0x51, 0x95, 0x3e, 0xb9, 0x61, 0x8e, 0x1c,
  0x9a, 0x1f, 0x92, 0x9a, 0x21, 0xa0, 0xb6, 0x85,
  0x40, 0xee, 0xa2, 0xda, 0x72, 0x5b, 0x99, 0xb3,
  0x15, 0xf3, 0xb8, 0xb4, 0x89, 0x91, 0x8e, 0xf1,
  0x09, 0xe1, 0x56, 0x19, 0x39, 0x51, 0xec, 0x7e,
  0x93, 0x7b, 0x16, 0x52, 0xc0, 0xbd, 0x3b, 0xb1,
  0xbf, 0x07, 0x35, 0x73, 0xdf, 0x88, 0x3d, 0x2c,
  0x34, 0xf1, 0xef, 0x45, 0x1f, 0xd4, 0x6b, 0x50,
  0x3f, 0x00];


/**
 * The base point in uncompressed form.
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.P_521.G = [0x04, /* uncompressed */
  // x
  0x00, 0xc6, 0x85, 0x8e, 0x06, 0xb7, 0x04, 0x04,
  0xe9, 0xcd, 0x9e, 0x3e, 0xcb, 0x66, 0x23, 0x95,
  0xb4, 0x42, 0x9c, 0x64, 0x81, 0x39, 0x05, 0x3f,
  0xb5, 0x21, 0xf8, 0x28, 0xaf, 0x60, 0x6b, 0x4d,
  0x3d, 0xba, 0xa1, 0x4b, 0x5e, 0x77, 0xef, 0xe7,
  0x59, 0x28, 0xfe, 0x1d, 0xc1, 0x27, 0xa2, 0xff,
  0xa8, 0xde, 0x33, 0x48, 0xb3, 0xc1, 0x85, 0x6a,
  0x42, 0x9b, 0xf9, 0x7e, 0x7e, 0x31, 0xc2, 0xe5,
  0xbd, 0x66,
  // y
  0x01, 0x18, 0x39, 0x29, 0x6a, 0x78, 0x9a, 0x3b,
  0xc0, 0x04, 0x5c, 0x8a, 0x5f, 0xb4, 0x2c, 0x7d,
  0x1b, 0xd9, 0x98, 0xf5, 0x44, 0x49, 0x57, 0x9b,
  0x44, 0x68, 0x17, 0xaf, 0xbd, 0x17, 0x27, 0x3e,
  0x66, 0x2c, 0x97, 0xee, 0x72, 0x99, 0x5e, 0xf4,
  0x26, 0x40, 0xc5, 0x50, 0xb9, 0x01, 0x3f, 0xad,
  0x07, 0x61, 0x35, 0x3c, 0x70, 0x86, 0xa2, 0x72,
  0xc2, 0x40, 0x88, 0xbe, 0x94, 0x76, 0x9f, 0xd1,
  0x66, 0x50];


/**
 * The order of the base point.
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.P_521.N = [
  0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xfa, 0x51, 0x86, 0x87, 0x83, 0xbf, 0x2f,
  0x96, 0x6b, 0x7f, 0xcc, 0x01, 0x48, 0xf7, 0x09,
  0xa5, 0xd0, 0x3b, 0xb5, 0xc9, 0xb8, 0x89, 0x9c,
  0x47, 0xae, 0xbb, 0x6f, 0xb7, 0x1e, 0x91, 0x38,
  0x64, 0x09];


/**
 * The field order for Curve25519: 2^255 - 19.
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.CURVE_25519.Q = [
  0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x100 - 19];


/**
 * The order of the base point.
 * @type {!e2e.ByteArray}
 */
e2e.ecc.constant.CURVE_25519.N = [
  0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x14, 0xde, 0xf9, 0xde, 0xa2, 0xf7, 0x9c, 0xd6,
  0x58, 0x12, 0x63, 0x1a, 0x5c, 0xf5, 0xd3, 0xed];
